package com.example.blog.Service;

import com.example.blog.model.BlogInfo;
import com.example.blog.model.UserInfo;
import com.example.blog.mapper.BlogInfoMapper;
import com.example.blog.mapper.UserInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    @Autowired
    public UserInfoMapper userInfoMapper;
    @Autowired
    private BlogInfoMapper blogInfoMapper;

    public UserInfo queryByName(String userName) {
        return  userInfoMapper.queryByName(userName);
    }

    public UserInfo getAuthorInfo(Integer blogId) {
        //1.根据博客ID，获取userId
        //2.根据userId,获取userInfo
        BlogInfo blogInfo=blogInfoMapper.queryBlogById(blogId);
        System.out.println("blogInfo.userid"+blogInfo.getUserid());
        if(blogInfo==null||blogInfo.getUserid()<0){
            return null;
        }
        return userInfoMapper.queryById(blogInfo.getUserid());
    }
    public UserInfo  queryById(Integer id){
        return userInfoMapper.queryById(id);
    }

}
